<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
<th:block th:include="include :: header('新增学习资料资源')" />
<th:block th:include="include :: bootstrap-fileinput-css" th:if="${material.type != 1}" />
<th:block th:include="include :: summernote-css" th:if="${material.type == 1}" />
</head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-res-add">
		    <input name="materialId" class="form-control" type="hidden" th:value="${materialId}">
			<div class="form-group" th:if="${material.type == 1}">
				<label class="col-sm-2 control-label">内容：</label>
				<div class="col-sm-10">
					<input id="content" name="content" type="hidden" required>
					<div id="editor" class="summernote"></div>
				</div>
			</div>
			<div class="form-group" th:if="${material.type != 1}">
				<label class="col-sm-2 control-label">文件</label>
				<div class="col-sm-10">
				    <input id="url" type="hidden" name="url"/>
				    <input id="size" type="hidden" name="size"/>
					<input id="file" name="file" type="file" class="file" data-show-preview="true"  data-show-caption="false"  data-show-upload="false" data-show-close="false">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">排序：</label>
				<div class="col-sm-10">
					<input name="seq" class="form-control" type="text" required>
				</div>
			</div>
		</form>
	</div>
	<th:block th:include="include :: footer" />
	<th:block th:include="include :: summernote-js" />
	<th:block th:include="include :: bootstrap-fileinput-js" />
	<script type="text/javascript">
		var prefix = ctx + "dict/res"
		$("#form-res-add").validate({
			focusCleanup : true
		});

		$(function() {
			$('.summernote').summernote({
				placeholder : '请输入内容',
				height : 400,
				lang : 'zh-CN',
				followingToolbar : false,
				callbacks : {
					onImageUpload : function(files) {

					}
				}
			});
			var content = $("#content").val();
			$('#editor').summernote('code', content);
		});
		
		var allowedFileExtensions = [];
		var type = [[${material.type}]];
		var dropZoneTitle ;
		if(type == 2){
			allowedFileExtensions = ['jpg', 'jpeg', 'png']
			dropZoneTitle = "支持jpg,jpeg,png格式图片"
		}else if(type == 3){
			allowedFileExtensions = ['zip', 'rar', 'pdf']
			dropZoneTitle = "支持zip,rar,pdf文件"
		}else if(type == 4){
			allowedFileExtensions = ['mp4']
			dropZoneTitle = "支持mp4视频"
		}
		
		$("#file").fileinput({
            'uploadUrl': '/common/uploadOSS',
            'dropZoneTitle': dropZoneTitle,
            'allowedFileExtensions': allowedFileExtensions
        }).on("fileuploaded", function(e, data, previewiId, index){
        	 console.log(data)
        	 $('#url').val(data.response.url);
        	 $('#size').val(data.files[0].size);
        }).on("filebatchselected", function(event, files) {
            $(this).fileinput("upload");
        });

		function submitHandler() {
			if ($.validate.form()) {
				var sHTML = $('.summernote').summernote('code');
				$("#content").val(sHTML);
				$.operate.save(prefix + "/add", $('#form-res-add').serialize());
			}
		}
	</script>
</body>
</html>